/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PackageMaker.Maker;

import java.util.ArrayList;

/**
 *
 * @author wcss
 */
public class ShPackageScriptMaker {

    public static String decompressScriptName = "decompress.sh";
    public static String installerDataPackageName = "InstallerData.tar.gz";
    public static String installerStartupScriptName = "start.sh";

    /**
     * 生成自动解压脚本
     *
     * @return
     */
    public static ArrayList<String> makeAutoDecompressScripts() {
        ArrayList<String> list = new ArrayList<String>();
        list.add("#!/bin/sh");
        list.add("( read l; read l; read l ;exec cat ) < \"$0\" | gunzip | tar xf - && ls -l && ./" + decompressScriptName);
        list.add("exit");
        return list;
    }

    /**
     * 生成数据释放脚本
     *
     * @return
     */
    public static ArrayList<String> makeDataDecompressScripts() {
        ArrayList<String> list = new ArrayList<String>();
        list.add("DIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"");
        list.add("rm -rf $DIR/.scriptinstaller");
        list.add("mkdir $DIR/.scriptinstaller");
        list.add("mv ./" + installerDataPackageName + " $DIR/.scriptinstaller/" + installerDataPackageName);
        list.add("cd  $DIR/.scriptinstaller");
        list.add("tar xvf " + installerDataPackageName);
        list.add("$DIR/.scriptinstaller/" + installerStartupScriptName);
        return list;
    }

    /**
     * 生成安装程序启动脚本(使用系统JRE)
     *
     * @return
     */
    public static ArrayList<String> makeInstallerStartupScripts() {
        ArrayList<String> list = new ArrayList<String>();
        list.add("DIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"");
        list.add("cd ..");
        list.add("rm -rf ./" + decompressScriptName);
        list.add("cd .scriptinstaller");
        list.add("java -jar ./installer/PackageInstaller.jar english $DIR/data");

        return list;
    }

    /**
     * 生成安装程序启动脚本(使用自带JRE)
     *
     * @return
     */
    public static ArrayList<String> makeInstallerStartupScriptsWithJre() {
        ArrayList<String> list = new ArrayList<String>();
        list.add("DIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"");
        list.add("cd ..");
        list.add("rm -rf ./" + decompressScriptName);
        list.add("cd .scriptinstaller");

        list.add("JAVA_HOME=$DIR/jrerun");
        list.add("PATH=$PATH:$JAVA_HOME/bin");
        list.add("export PATH JAVA_HOME");

        list.add("java -jar ./installer/PackageInstaller.jar english $DIR/data");

        return list;
    }
}